﻿using Microsoft.EntityFrameworkCore;
using PioneerBoilerplate.Model.Admin;
using PioneerBoilerplate.Repository.UnitOfWorks;

namespace PioneerBoilerplate.Repository
{
    public class PermissionRepository : BaseRepository<ApplicationDbContext, PermissionEntity>, IPermissionRepository
    {
        private readonly IUnitOfWorkManager _unitOfWorkManager;
        public PermissionRepository(IUnitOfWorkManager muowm) : base(muowm)
        {
        }

        DbContext IBaseRepository<DbContext, PermissionEntity>.CurrentDbContext => AsyncLocalCurrentUnitOfWorkHandleProvider<ApplicationDbContext>.Current?.GetActiveUnitOfWork();

        IUnitOfWorkHandle<DbContext> IBaseRepository<DbContext, PermissionEntity>.BeginNewUnitOfWork()
        {
            return _unitOfWorkManager.BeginNew<DbContext>();
        }

        IUnitOfWorkHandle<DbContext> IBaseRepository<DbContext, PermissionEntity>.BeginUnitOfWork()
        {
            return _unitOfWorkManager.Begin<DbContext>();
        }
    }
}
